package com.nnnu.orange.pojo.entity;

import java.math.BigDecimal;

import com.baomidou.mybatisplus.annotation.*;

import java.time.LocalDateTime;
import java.io.Serializable;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;

/**
 * <p>
 * 记录用户借阅图书的信息
 * </p>
 *
 * @author zk
 * @since 2024-11-07
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("borrowings")
@ApiModel(value = "Borrowings对象", description = "记录用户借阅图书的信息")
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Borrowings implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "借阅记录唯一标识")
    @TableId(value = "borrowing_id", type = IdType.AUTO)
    private Integer borrowingId;

    @ApiModelProperty(value = "用户ID（关联users表）")
    private Integer userId;

    @ApiModelProperty(value = "图书ID（关联books表）")
    private Integer bookId;

    @ApiModelProperty(value = "借阅日期")
    private LocalDateTime borrowDate;

    @ApiModelProperty(value = "实际归还日期")
    private LocalDateTime returnDate;

    @ApiModelProperty(value = "应还日期")
    private LocalDateTime dueDate;

    @ApiModelProperty(value = "借阅状态")
    private Integer status;

    @ApiModelProperty(value = "逾期罚款")
    private BigDecimal fine;

    @ApiModelProperty(value = "备注（如损坏等）")
    private String notes;

    @ApiModelProperty(value = "借阅记录创建时间")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createdAt;

    @ApiModelProperty(value = "借阅记录更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;


    // 状态常量
    public static final int STATUS_PENDING = 0;
    public static final int STATUS_CONFIRMED = 1;
    public static final int STATUS_CANCELLED = 2;

    //返回状态名称
    public static String getStatusDescription(int status) {
        return switch (status) {
            case STATUS_PENDING -> "逾期";
            case STATUS_CONFIRMED -> "借阅中";
            case STATUS_CANCELLED -> "已归还";
            default -> "未知状态";
        };
    }
}
